<?


if (!function_exists('ppr'))
 {
     function ppr($var)
     {
         echo '<pre>';
         print_r($var);
         echo '</pre>';
    
     }
 }
 
 if (!function_exists('ppre'))
 {
     function ppre($var)
     {
         ppr($var);
         exit;
     }
 }
 

function formulaires_ecatalogue_prices_group_charger_dist() {    
	$valeurs = array(); 
	
	return $valeurs;
}


function formulaires_ecatalogue_prices_group_verifier_dist(){
    $erreurs = array();
	$is_active = _request('is_active');
	$prices_group = _request('price');
	$elements_insert = _request('elements_insert');
	
	
         
	return $erreurs;
}


function formulaires_ecatalogue_prices_group_traiter_dist() {
    $result = array();
	
	  $is_active = _request('is_active');
	  $prices_group = _request('price');
	  $elements_insert = _request('elements_insert');
	  $isset_price_group = sql_select('*','spip_ecatalogue_prices_group');
    
    
     if ($isset_price_group)
     {
          while ($row = sql_fetch($isset_price_group))
          {
	            
              $id_price_group = $row['id_group'];
              if (isset($prices_group[$id_price_group]))
              {
                  $name = $prices_group[$id_price_group];
                  $status = isset($is_active[$id_price_group])?1:0;
                  
                  sql_update('spip_ecatalogue_prices_group',array('titre'=>'"'.$name.'"','is_active'=>$status),'id_group = '.(int)$id_price_group);
                    
              }
              else
              {
                  sql_delete('spip_ecatalogue_prices_group','id_group = '.$id_price_group);
              // Delete price group
              }
              
          }
     
     }
    
     if (is_array($elements_insert)&&(!empty($elements_insert)))
     {
        foreach($elements_insert as $key=>$value)
        {
            $name = $value['titre'];
            $is_active = isset($value['is_active'])?1:0;
            sql_insert('spip_ecatalogue_prices_group', '(titre,is_active)', '("'.$name.'",'.$is_active.')');        
        
        } 
     }
    
	return $result;    
}
?>